/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */
package info.peigen.hotpot.component.gateway.core.http;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

/**
 * <b>(OkHttpClientUtil)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/4/8
 */
public class OkHttpClientUtil {
    private final static int          CONNECT_TIMEOUT = 3000;
    private final static int          READ_TIMEOUT    = 3000;
    private final        OkHttpClient okHttpClient;

    private OkHttpClientUtil() {
        okHttpClient = new OkHttpClient.Builder()
                .connectionPool(new ConnectionPool(50, 10, TimeUnit.MINUTES))
                .connectTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)
                .readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS)
                .build();
    }

    public static OkHttpClient getInstance() {
        return OkHttpHolder.INSTANCE.okHttpClient;
    }

    private static class OkHttpHolder {
        private static final OkHttpClientUtil INSTANCE = new OkHttpClientUtil();
    }
}